package com.vinoxm.infoc.service;

import com.vinoxm.infoc.dao.TOTPDao;
import com.vinoxm.common.base.exception.BusinessException;
import com.vinoxm.common.utils.StringUtils;
import com.vinoxm.common.utils.TOTP;
import com.vinoxm.infoc.model.SteamAccount;
import org.springframework.stereotype.Service;

@Service
public class TOTPService extends BaseService<TOTPDao> {

    public String steamAccountToken(String name) {
        if (StringUtils.isEmpty(name)) throw new BusinessException("AccountName is empty!");
        SteamAccount account = baseDao.selOneByName(name);
        if (account == null) {
            throw new BusinessException(String.format("User %s not exists!", name));
        }
        return TOTP.generateSteamTOTP(account.getSharedSecret());
    }
}
